#coding=utf-8

import time,mmap
import numpy
from threading import Thread

from multiprocessing import Manager, Process, Queue, Value

image_queue = Queue()
        
is_exit == 0
def pic_receive_thread():
    try:
        with open(share_path, "r+b") as f:
            mm = mmap.mmap(f.fileno(), 0)
            while True:
                try:
                    res = sfull.acquire(0.2)
                except Exception as e:
                    # print('acquire full error.')
                    print("not read data:" + str(e))
                    continue
                print(" read data")
                fcntl.flock(f, fcntl.LOCK_EX)
                print(" numpy.ndarray 1")
                img = numpy.ndarray(shape=shape, dtype=numpy.uint8, buffer=mm).copy()
                print(" numpy.ndarray 2")
                fcntl.flock(f, fcntl.LOCK_UN)
                image_queue.put((0, img))
                print("image_queue.put((0, img))")
                sempty.release()
    except Exception as e:
        image_queue.put((None, str(e)))

    print('pic recevie quit')
      
def pic_save_thread():
    image_number = 0 
    save_index = 0
    print("image_number")
    while True:
        image_number = image_number + 1
        print("image_number 1 " + str(image_number))
        sn, img = image_queue.get()
        print("image_number " + str(sn))
        print("save index:" + str(sn))
        if save_index < 100:        
            cv2.imwrite("/tmp/hi/" + save_index + '.jpg', img)
            print("save index:" + str(save_index))
        save_index = save_index + 1
        time.sleep(10)


receive_thread = Thread(target=pic_receive_thread)
receive_thread.start()
receive_thread.join()

sempty.close()
full.close()
sempty = None
sfull = None
print('DataTransport quit')